package cn.tqfeiyang.smartadmin.business.organization.controller;

import cn.tqfeiyang.smartadmin.business.organization.constant.AddressConstants;
import cn.tqfeiyang.smartadmin.business.organization.service.AddressExcelService;
import cn.tqfeiyang.smartadmin.business.organization.request.AddressQueryDTO;

import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.multipart.MultipartFile;
import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import cn.tqfeiyang.smartadmin.commons.response.ApiResult;
import cn.tqfeiyang.smartadmin.commons.logging.OperationLog;

/**
 * 地址Excel控制器
 *
 * @author tqfeiyang
 * @since 2024-10-18
 */
@RestController
@Validated
@RequestMapping(AddressConstants.REQUEST_URL)
@Tag(name = AddressConstants.API_TAG)
public class AddressExcelController {

    /**
     * 地址Excel服务
     */
    @Resource
    private AddressExcelService addressExcelService;

    /**
     * 导出地址Excel
     */
    @OperationLog
    @GetMapping("/exportAddressesToExcel")
    @Operation(summary = "地址 - 导出地址Excel")
    @SaCheckPermission(AddressConstants.PERMISSION + "exportAddressesToExcel")
    public void exportAddressesToExcel(@Validated AddressQueryDTO dto) {
        addressExcelService.exportAddressesToExcel(dto);
    }

    /**
     * 下载地址模板
     */
    @OperationLog
    @GetMapping("/downloadAddressTemplate")
    @Operation(summary = "地址 - 下载地址模板")
    @SaCheckPermission(AddressConstants.PERMISSION + "downloadAddressTemplate")
    public void downloadAddressTemplate() {
        addressExcelService.downloadAddressTemplate();
    }

    /**
     * 导入地址Excel
     */
    @OperationLog
    @PostMapping("/importAddressesFromExcel")
    @Operation(summary = "地址 - 导入地址Excel")
    @SaCheckPermission(AddressConstants.PERMISSION + "importAddressesFromExcel")
    public ApiResult importAddressesFromExcel(MultipartFile file) {
        addressExcelService.importAddressesFromExcel(file);
        return ApiResult.success();
    }
}
